package com.CuandoLlegaAndroid.Custom;

import com.CuandoLlegaAndroid.R;
import com.CuandoLlegaAndroid.R.anim;
import com.CuandoLlegaAndroid.R.id;
import com.CuandoLlegaAndroid.R.layout;
import com.CuandoLlegaAndroid.R.style;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomProgress {

	private Context context;
	private Dialog pDialog;

	/**
	 * Public constructor for custom dialog
	 */
	public CustomProgress(Context t) 
	{
		this.context = t;
	}

	/**
	 * Close Dialog
	 */
	public void DismissProgress()
	{
		pDialog.dismiss();
	}

	/**
	 * Show progress dialog
	 * @param message
	 */
	public void ShowProgress(String message) 
	{
		//get the LayoutInflater and inflate the custom_toast layout
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View layout = inflater.inflate(R.layout.progressbar, null);

		//get the ImageView
		ImageView imgOuter = (ImageView) layout.findViewById(R.id.imagenOuter);
		ImageView imgInner = (ImageView) layout.findViewById(R.id.imagenInner);

		//get the animation
		Animation anim = AnimationUtils.loadAnimation(context, R.anim.spinner_outer_anim);
		Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.spinner_inner_anim);

		//get the TextView
		TextView text = (TextView) layout.findViewById(R.id.loadingText);
		text.setText(message);

		//create custom dialog with style
		pDialog = new Dialog(context, R.style.Dialog);
		pDialog.setCancelable(false);
		pDialog.setCanceledOnTouchOutside(false);

		//set View
		pDialog.setContentView(layout);

		//set animation
		imgOuter.startAnimation(anim);
		imgInner.startAnimation(anim2);

		//show dialog
		pDialog.show();
	}

}
